GenerativeComponents Help

Calling functions

Functions allow you to organize code into modules that do specific tasks. Calling functions allows you to easily utilize this encapsulated functionality. Writing code in functions makes code more reusable. The same function can be called repeatedly again and again.

In GenerativeComponents it is possible to distinguish between three types of functions: local functions that are local in scope, global functions that are global in scope and anonymous functions. Functions which are global in scope can be called anywhere within a transaction file. Functions which are local in scope are callable only locally within the scope of the function. GenerativeComponents has a number of built-in global functions such as Abs(), Cos(), MembersAt(), and Series().

Functions can be called in one of two ways. The usual way is by calling the function directly by name followed by a list of the arguments

functionName(functionArguments);

A second way is normally only used in very particular circumstances uses the GC script function CallFunction:

CallFunction(string functionName, functionArguments …)

When calling a function the arguments must be listed in the same order as they are defined in the function. The values must also be of the same type as specified by the function arguments. In the first example below, the built-in global function Series() accepts three arguments all of which must be numbers and returns a single array of numbers. In the second example below, the built-in global function Abs() takes a number input and returns a number

transaction script 'New script transaction'
{
	double list = SeriesByCount(0, 10, 2.5); 
	//list has the value {0.0, 2.5, 5.0, 7.5, 10.0}
}
transaction script 'New script transaction'
{
	double theta = -53.2;
	double result  = Abs(theta); 
	//result has the value 53.2
}
Note: To see the results in the a above transactions, you must open the console window by selecting (Script Console ).